import { getAllGoods } from '@/api/index'

const state = {
  goodsList: {},
}

const actions = {
  // 1、获取商品列表数据
  async getGoodsList({ commit }, params) {
    const result = await getAllGoods(params)
    console.log(result)
    if (result.code === 200) {
      commit('SAVE_GOOD_LIST', result.result)
    } else {
      console.log(result.message)
    }
  },
}

const mutations = {
  SAVE_GOOD_LIST(state, payload) {
    state.goodsList = payload // 是个对象形式
  },
}
const getters = {}

export default {
  namespaced: true, // 开启命名空间
  state,
  actions,
  mutations,
  getters,
}
